<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ppctu="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="./Template/Template.xhtml">

            <ui:define name="title">
                Save XML to Database
            </ui:define>

            <ui:define name="top">
                Save XML to Database
            </ui:define>

            <ui:define name="left">
                Menu
            </ui:define>

            <ui:define name="content">
                Import CDs to Database
                <br/>

                <h:form>
                    <ppctu:messages id="msg" showDetail="true" showSummary="true"/>
                    <br/><br/>
                    <ppctu:fileUpload allowTypes="*.xml;" 
                                      description="File XML" 
                                      fileUploadListener="#{mainController.uploadXMLFiles}"
                                      multiple="true" 
                                      update="display,xmlcontent,xmlList,history"/>

                    <br/><br/>
                    <h:outputLink value="javascript:void(0)" onclick="History.show()">
                        <i>Uploaded files</i></h:outputLink>  
                    <br/><br/>

                    <ppctu:dialog widgetVar="History" header="uploaded files" width="450" 
                                  resizable="true" showEffect="fold" hideEffect="clip">
                        <ppctu:outputPanel id="history">
                            <h:panelGrid columns="1" style="text-align: center;">
                                <h:outputText style="font-weight: 700" value="xml files"/>

                                <h:selectOneListbox id="xmlList" value="#{mainController.xmlFile}" style="min-width: 100px; height: 150px;">
                                    <f:selectItems value="#{fileList.xmlKeys}"/>
                                    <ppctu:ajax update="display,xmlcontent"/>
                                </h:selectOneListbox>
                            </h:panelGrid>
                        </ppctu:outputPanel>
                    </ppctu:dialog>

                    <ppctu:dialog widgetVar="xmldialog" header="XML File : #{mainController.xmlFile}" width="450" 
                                  height="500" resizable="true" showEffect="fold" hideEffect="clip" >  
                        <pre><h:outputText id="xmlcontent"  value="#{mainController.xmlFileContent}"/></pre>
                    </ppctu:dialog>

                    <ppctu:outputPanel id="display">
                        XML File :<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <h:outputLink value="javascript:void(0)"  onclick="xmldialog.show()">
                            <h:outputLabel value="#{mainController.xmlFile}" escape="false"/>
                        </h:outputLink> 
                        <br/><br/><br/>


                        <h:commandButton value="Import CDs" action="#{mainController.importToDatabase}" disabled="#{!mainController.dbReady}"/>
                    </ppctu:outputPanel>
                </h:form>

            </ui:define>

            <ui:define name="bottom">
                bottom
            </ui:define>

        </ui:composition>

    </body>
</html>
